Overview
Polynomial evaluation is a fundamental operation in homomorphic encryption with applications in:- Private function evaluation
- Approximating non-linear functions
- Machine learning activation functions
- Statistical computations
Basic polynomial: f(x) = x³ + 2x² + 3x + 4
Let’s evaluate a cubic polynomial at x = 5:1
Encrypt the input and coefficients
First, encrypt the input value and any coefficients needed:
2
Compute powers of x
Calculate x², x³ homomorphically:
3
Evaluate the polynomial
Combine the terms using homomorphic operations:
You can also write this more compactly as a single nested expression.
4
Decrypt and verify
Decrypt the result and verify correctness:
Complete example
Here’s the full code for evaluating f(x) = x³ + 2x² + 3x + 4:Optimizing polynomial evaluation
Using Horner’s method
For better efficiency, use Horner’s method to reduce the number of multiplications:Using constant multiplication
When coefficients are public, usect_mul_const for better performance:
Higher-degree polynomials
Computing high powers efficiently
Use repeated squaring for efficient power computation:The circuit depth grows logarithmically with the exponent when using repeated squaring, making it practical to compute high powers.
Circuit depth analysis
Different evaluation strategies result in different circuit depths:L.size() field shows the number of layers (circuit depth), while E.size() shows the total number of edges in the computation graph.
Nested expressions
Evaluate complex nested expressions:Multivariate polynomials
Evaluate polynomials with multiple variables:Applications
Activation functions in ML
Polynomials can approximate non-linear activation functions:Private threshold functions
Evaluate comparison thresholds privately:Performance considerations
Source code
The polynomial evaluation example is part of the basic usage tests:examples/basic_usage.cpp(lines 137-148)
Next steps
Basic usage
Learn the fundamentals of PVAC-HFHE
ML credit scoring
Apply polynomials in encrypted ML models